package test07;

import java.util.*; /**
 * 审核监控器
 */
public class AuditMonitor {
    private List<String> auditLogs;
    private Map<String, Object> statistics;

    public AuditMonitor() {
        this.auditLogs = new ArrayList<>();
        this.statistics = new HashMap<>();
        initializeStatistics();
    }

    private void initializeStatistics() {
        statistics.put("totalProcessed", 0);
        statistics.put("blockedCount", 0);
        statistics.put("reviewCount", 0);
        statistics.put("averageProcessingTime", 0.0);
    }

    public void recordAudit(ContentCheckRequest request, CheckResult result) {
        String log = String.format("[%s] 内容ID: %s, 风险等级: %s, 结果: %s",
                new Date(), request.getContentId(),
                request.getRiskLevel(), result.getMessage());
        auditLogs.add(log);

        // 更新统计信息
        statistics.put("totalProcessed", (Integer)statistics.get("totalProcessed") + 1);
        if (result.getRiskLevel() == RiskLevel.HIGH) {
            statistics.put("blockedCount", (Integer)statistics.get("blockedCount") + 1);
        }
        if ("REVIEW".equals(result.getAction())) {
            statistics.put("reviewCount", (Integer)statistics.get("reviewCount") + 1);
        }
    }

    public Map<String, Object> getStatistics() {
        return new HashMap<>(statistics);
    }

    public void generateReport() {
        System.out.println("\n📊 审核统计报告");
        System.out.println("========================");
        statistics.forEach((key, value) -> {
            System.out.printf("%s: %s%n", key, value);
        });
        System.out.println("========================");
    }
}
